<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 
    Object->Person/eat->Student/study->xialuo（实例）
    major专业
     -->
    <script>
        /* 封装Person类（构造函数） */
        function Person(name,age){
            this.name = name
            this.age = age
        }

        Person.prototype.eat = function(){
            console.log(`${this.name}正在饕餮`);
        }
        // const xialuo = new Person("夏洛",18)
        // // console.dir(xialuo)
        // xialuo.eat()

        /* 封装Person子类Student */
        function Student(name,age,major){
            // this.name = name
            // this.age = age

            /* 继承父类属性 */
            Person.call(this,name,age)

            // Student实例独有的属性【专业】
            this.major = major
        }

        /* Student认Person做父类（娶一个Person家的姑娘当老婆），从而继承Person实例的所有方法 */
        Student.prototype = new Person()

        /* 让所有Student实例都会学习 */
        Student.prototype.study = function(){
            console.log(`${this.name}正在钻研${this.major}`);
        }

        const xialuo = new Student("夏洛",18,"H5")

        // 继承于Person Person.prototype=>Student.prototype（xialuo.__proto__）=>xialuo
        xialuo.eat()

        // 继承于Student Student.prototype（xialuo.__proto__）=>xialuo
        xialuo.study()
        
        // 继承于Object Object.prototype=>Person.prototype=>Student.prototype（xialuo.__proto__）=>xialuo
        console.log(xialuo.toString());
        console.log(Object.prototype.toString.call(xialuo));
        
    </script>
</body>

</html>